package light.head.dao.el;

import java.util.List;

import org.springframework.stereotype.Service;

import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.model.el.TopicRecord;
@Service
public class TopicRecordDAO extends BaseDAO<TopicRecord, Integer>{
	private final static String hql_findByErc = "FROM TopicRecord tr WHERE tr.deleted = 0 AND tr.erc = ?";
	/**
	 * 通过考试记录编号 查找题目记录
	 * @param erCode
	 * @return
	 */
	public List<TopicRecord> findByErc(Integer erCode){
		if(erCode != null){
			return find(hql_findByErc, erCode);
		}
		return null;
	}
	
	/**
	 * 更新数据
	 */
	public RESULT update(TopicRecord tr){
		if(tr == null || tr.getCode() == null){
			return RESULT.ERROR;
		}
		TopicRecord old = get(tr.getCode());
		if(tr.getDeleted() != null && tr.getDeleted() != old.getDeleted()){
			old.setDeleted(tr.getDeleted());
		}
		if(tr.getCu() != null && tr.getCu() != old.getCu()){
			old.setCu(tr.getCu());
		}
		if(tr.getErc() != null && tr.getErc() != old.getErc()){
			old.setErc(tr.getErc());
		}
		if(tr.getOc() != null && tr.getOc() != old.getOc()){
			old.setOc(tr.getOc());
		}
		if(tr.getPoint() != null && tr.getPoint().floatValue() != old.getPoint().floatValue()){
			old.setPoint(tr.getPoint());
		}
		if(tr.getTc() != null && tr.getTc() != old.getTc()){
			old.setTc(tr.getTc());
		}
		if(tr.getPoints() != null && tr.getPoints().floatValue() != old.getPoints().floatValue()){
			old.setPoints(tr.getPoints());
		}
		return upd(old);
	}
}
